package JDBC1;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

//演示select语句返回Resultset，并取出结果
public class A6 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
        Properties properties = new Properties();
        properties.load(new FileInputStream("D:\\java作业\\java78\\java~gaoji\\src\\JDBC1\\mysql.properties"));
        //获取相关的值
        String user=properties.getProperty("user");
        String password=properties.getProperty("password");
        String driver = properties.getProperty("driver");
        String url = properties.getProperty("url");
        Class.forName(driver);//建议写上
        Connection connection = DriverManager.getConnection(url, user, password);
        Statement statement = connection.createStatement();
        String sql="select * from `s_subject` ";
        ResultSet resultSet = statement.executeQuery(sql);
        //5.使用while取出数据
        while (resultSet.next()){
            int id = resultSet.getInt(1);
            String subjectname=resultSet.getString(2);
            int classhour = resultSet.getInt(3);
            int gradeid = resultSet.getInt(4);
            System.out.println(id+" "+subjectname+" "+classhour+" "+gradeid);
        }
        //6.关闭连接
        resultSet.close();
        statement.close();
        connection.close();

    }
}
